﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data;
using CMP.ERP.Admin.ServiceReference1;
namespace CMP.ERP.Admin.Controllers
{
    public class BlurbController : Controller
    {
        //
        // GET: /Blurb/
        ServiceReference1.Service1Client client = new Service1Client();//实例化代理类
        /// <summary>
        /// 显示物品信息
        /// </summary>
        /// <returns></returns>
        public ActionResult Blurb_Show()
        {
            ViewBag.TypeID = new SelectList(client.showGoodsType().ToList(), "TypeID", "TypeName");
            return View(client.Goodshow().ToList());
        }
        /// <summary>
        /// 添加物品信息
        /// </summary>
        /// <param name="ss"></param>
        /// <returns></returns>
        public ActionResult AddComodity(GoodsInfo ss)
        {
            if(client.addGoods(ss)>0)
            {
                return Content("<script>alert('添加成功'); location.href='/Blurb/Blurb_Show'</script>");
            }
            else
            {
                return Content("<script>alert('添加失败'); location.href='/Blurb/Blurb_Show'</script>");
            }
        }

        /// <summary>
        /// 删除名称信息
        /// </summary>
        /// <param name="ss"></param>
        /// <returns></returns>
        public ActionResult DelComodity(int id)
        {
            if (client.deleteGoods(id) > 0)
            {
                return Content("<script>alert('删除成功'); location.href='/Blurb/Blurb_Show'</script>");
            }
            else
            {
                return Content("<script>alert('删除失败'); location.href='/Blurb/Blurb_Show'</script>");
            }
        }
        /// <summary>
        /// 根据姓名搜索物品表信息
        /// </summary>
        /// <param name="GoodsName"></param>
        /// <returns></returns>
        public ActionResult SearchGoods(string GoodsName)
        {
            ViewBag.TypeID = new SelectList(client.showGoodsType().ToList(), "TypeID", "TypeName");
            List<ServiceReference1.GoodsInfo> go = client.SearchGoods(GoodsName).ToList();
            return View("Blurb_Show",go);
        }
        /// <summary>
        /// 修改视图
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult UptGoodsShow(int id)
        {
            ViewBag.TypeID = new SelectList(client.showGoodsType().ToList(), "TypeID", "TypeName");
            return View(client.GetGoodsByID(id));           
        }
        /// <summary>
        /// 修改的方法
        /// </summary>
        /// <param name="g"></param>
        /// <returns></returns>
        public ActionResult UptGoods(GoodsInfo g)
        {
            if (client.UptGoods(g) > 0)
            {
                return Content("<script>alert('修改成功');location.href='/Blurb/Blurb_Show'</script>");
            }
            else
            {
                return Content("<script>alert('修改失败');location.href='/Blurb/Blurb_Show'</script>");
               
            }
        }
     

    }
}
